package cn.mysource.org.controller;

import cn.mysource.basic.util.AjaxResult;
import cn.mysource.basic.util.PageList;
import cn.mysource.org.domain.Dictionarydetail;
import cn.mysource.org.domain.Dictionarytype;
import cn.mysource.org.domain.Permission;
import cn.mysource.org.query.DictionarydetailQuery;
import cn.mysource.org.query.DictionarytypeQuery;
import cn.mysource.org.query.PermissionQuery;
import cn.mysource.org.service.IDictionarydetailService;
import cn.mysource.org.service.IDictionarytypeService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/type")
public class DictionarytypeController {

    @Autowired
    private IDictionarytypeService dictionarytypeService;

    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询详情" )
    public Dictionarytype findById(@ApiParam(value="部门id",required = true) @PathVariable("id") Long id) {
        return dictionarytypeService.findById(id);

    }


    @GetMapping()
    public List<Dictionarytype> findAll() {
        return dictionarytypeService.findAll();
    }

    @PutMapping()
    public AjaxResult addOrUpdate(@RequestBody Dictionarytype dictionarytype) {
        if (null != dictionarytype.getId()) {
            // 修改
            dictionarytypeService.update(dictionarytype);
        } else {
            // 添加
            dictionarytypeService.add(dictionarytype);
        }
        return AjaxResult.me().success();
    }

    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id) {
        dictionarytypeService.delete(id);
        return AjaxResult.me().success();
    }

    //分页查询
    @PostMapping()
    public PageList<Dictionarytype> queryByPage(@RequestBody PermissionQuery query) {

        return (PageList<Dictionarytype>) dictionarytypeService.queryByPage(query);

    }
    //批量删除
    @PatchMapping()
    public AjaxResult batchDelete(@RequestBody List<Long> ids) {
        dictionarytypeService.batchDelete(ids);
        return AjaxResult.me().success();
    }

}
